<?php namespace App\Admin\Goods\JmThemeGoods\Criterias;

use Input;
use App\Core\Repository\Criteria;
use App\Core\Repository\Repository;
//基础条件
use App\Core\Repository\Criterias\NotDeleteCriteria;
use App\Core\Repository\Criterias\FixedCriteria;
//Cabinet
use App\Admin\Goods\JmTheme\Repository as JmThemeRepository;

class MatchSchedule extends Criteria{

    public function apply(Repository $repository){
        parent::apply($repository);
        $thmemId = Input::get('theme_id');
        if(!$thmemId || !is_numeric($thmemId)){
            return $this->query->whereRaw('1=0');
        }
        $this->thmemId = $thmemId;
        $rep = new JmThemeRepository();
        $rep->addCriteria(new NotDeleteCriteria());
        $rep->addCriteria(new FixedCriteria('id', $thmemId));
        $theme = $rep->first();
        if($theme){
            $field = $this->formatField($this->model, 'theme_id');
            $this->query->where($field, '=', $theme->id);
            return ;
        }
        $this->query->whereRaw('1=0');
    }
}